<template>
    <el-form ref="form" :model="form" label-width="80px" size="mini">
        <label >消息发布</label><br></br>

        <!-- <el-form-item label="标题" prop="title">
            <el-input v-model="form.title"></el-input>
        </el-form-item> -->
        <el-form-item label="消息内容" prop="content">
            <el-input type="textarea" v-model="form.content"></el-input>
        </el-form-item>
        
        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即发布</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</template>


<script>
import distributeApi from '@/api/distribute'
import $ from 'jquery'
import Qs from 'qs'
import axios from 'axios'
export default {
    
    data() {
      return {
        form: {
          content: '',
        },
        BASE_API: process.env.BASE_API,
      }
    },
    methods: {
      onSubmit() {
        // let content={}
        // content.content=this.content
        
        // console.log(content)
        // $.ajax({
        //   type: 'post',
        //   url: this.BASE_API+'/system/message2/add',
        //   dataType: 'json',
        //   data: content,
        //   success: function (data) {
           
        //     console.log(data)
        //     success()
        //     this.$refs['form'].resetFields()
        //   },
        //   error: function (xhr, textStatus, errorThrown) {
        //     that.errDialogVisible = true
        //   }
        // })
        let url=this.BASE_API+'/system/message2/add'
        const fd=new FormData()
        fd.append('content',this.form.content)
        axios.post(url, fd, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).then(res => {
          if (res.data.code === 0) {
            // 提示信息
            this.$message({
              type: 'success',
              message: '消息发布成功!'
            })
            this.$refs['form'].resetFields()
            // this.$router.go(-1)
          }
        }).catch(error => {
          alert('消息发布失败' + error)
        })

        

        // distributeApi.distributeMessage(content)
        // .then(response=>{
        //    // 提示信息
        //   this.$message({
        //     type: 'success',
        //     message: '消息发布成功!'
        //   })
        //   // this.$router.go(0)
        //   // 清空消息发布表单
        //   // this.$refs.form.resetFields();
        // })

        
      },
      success(){
         // 提示信息
        this.$message({
          type: 'success',
          message: '消息发布成功!'
        })
      }
    }
}
</script>

<style>

</style>

